package com.kingwood.algorithm.test200;

import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: 园区参观路径
 * https://blog.csdn.net/qfc_128220/article/details/134635868
 * @Date: 2024/3/29 18:12
 * @Modified By：
 * @Version 1.0
 */

public class YuanQuCanGuanPath {

    public static long getPathNumber(int[][] matrix, int n, int m) {
        if (matrix[0][0] == 1 || matrix[n-1][m-1] == 1) {
            return 0;
        }

        long[][] dp = new long[n][m];
        dp[0][0] = 1;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == 1) {
                    continue;
                }

                if (i > 0) {
                    dp[i][j] += dp[i-1][j];
                }

                if (j > 0) {
                    dp[i][j] += dp[i][j-1];
                }
            }
        }

        return dp[n-1][m-1];
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 长 行数
        int m = scanner.nextInt(); // 宽 列数

        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                matrix[i][j] = scanner.nextInt();
            }
        }

        long ans = getPathNumber(matrix, n, m);
        System.out.println(ans);
    }
}
